<?php
include_once XXF_EXCEL;
class Fxy_sf_ctl extends Ctl{
    function __construct(){
    }
    function main(array $xxfget) {
        $this::sessver();
        $type=!empty($xxfget['type'])?$xxfget['type']:false;
        if(!$type){
            $pid=$xxfget['pid'];
        	$result=xdb::getInstance()->getarray('select * from peixunxueyuan where pid='.$pid);
        	$this::show('fxy_sf',compact('result','pid'));
        }elseif ($type=="down"){
        	$pid=$xxfget['pid'];
        	$result=xdb::getInstance()->getarray('select * from peixunban as pb,peixunxueyuan as px where pb.id=px.pid and px.pid='.$pid);
        	$xtitle=array("A","B","C","D","E","F","G","H","I","J","K");
        	$xhead=array("班级名称","工作单位","学生姓名","电话","学费","财务收费床位类型","招待所床位类型","财务备注","招待所备注","是否欠费","入住时间","住宿房号");
        	$xsu=array("pname","workunit","puname","mphone","xuefei","flevel","zlevel","fbeizhu","zbeizhu","qianfei","ztime","fangnum");
        	$excel = new PHPExcel();
            $excel->getActiveSheet()->setTitle('学费统计');
            $es=$excel->getActiveSheet();
            for($i=0;$i<count($xtitle);$i++){
                $es->setCellValue($xtitle[$i]."1",$xhead[$i]);
            }
            $j=1;
            foreach ($result as $row){$j++;
                for($i=0;$i<count($xtitle);$i++){
                    $es->setCellValue($xtitle[$i].$j,$row[$xsu[$i]]);
                }
            }
            $es->getStyle('A1:K1')->applyFromArray(//添加边框
                array(
                    'font'    => array(
                       'bold'      => true
                  )
                )
             );
            $es->getStyle('A1:K'.($j))->applyFromArray(//添加边框
                array(
                    'borders'=>array(
                        'allborders'=>array(
                            'style'=>PHPExcel_Style_Border::BORDER_THIN
                        )
                    )
                )
            );
            $stywidth=array(//表格宽度设置
                'A'=>20,'B'=>20,'C'=>12,'D'=>12,'E'=>19,'F'=>16,'G'=>12,'H'=>12,'I'=>12,'J'=>12,'K'=>12
            );
            foreach ($stywidth as $k=>$v){
                $es->getColumnDimension($k)->setWidth($v);
            }
            $es->getStyle('A1:K'.$j)->getAlignment()->setWrapText(true);
            $es->getStyle('A1:K'.$j)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
            $es->getStyle('A1:K'.$j)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
            $write = new PHPExcel_Writer_Excel5($excel);
            header("Pragma: public");
            header("Expires: 0");
            header("Cache-Control:must-revalidate, post-check=0, pre-check=0");
            header("Content-Type:application/force-download");
            header("Content-Type:application/vnd.ms-execl");
            header("Content-Type:application/octet-stream");
            header("Content-Type:application/download");;
            header('Content-Disposition:attachment;filename="'.xdb::getInstance()->getvar("select pname from peixunban where id=".$pid)."学费统计表".'.xls"');
            header("Content-Transfer-Encoding:binary");
            $write->save('php://output');
        }
    }
}